local chunrijishi = fk.CreateSkill{
  name = "hanqing__chunrijishi",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["hanqing__chunrijishi"] = "春日计时",
  [":hanqing__chunrijishi"] = "锁定技，你视为不在游戏内，<font color='red'>♥</font>牌进入弃牌堆时改为置于你武将牌上。当你武将牌上有三张牌后，"..
  "你获得这些牌、〖奋音〗和〖咆哮〗，失去本技能。",

  ["$hanqing__chunrijishi1"] = "欸咿欸咿欸咿欸哦哦，欸咿欸咿欸咿欸哦哦~",
  ["$hanqing__chunrijishi2"] = "恭！喜！发！财！",
}

chunrijishi:addEffect(fk.GameStart, {
  derived_piles = chunrijishi.name,
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(chunrijishi.name)
  end,
  on_refresh = function (self, event, target, player, data)
    table.removeOne(player.room.alive_players, player)
  end,
})

chunrijishi:addEffect(fk.AfterCardsMove, {
  audio_index = 1,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(chunrijishi.name) then
      local ids = {}
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).suit == Card.Heart then
              table.insertIfNeed(ids, info.cardId)
            end
          end
        end
      end
      ids = table.filter(ids, function (id)
        return table.contains(player.room.discard_pile, id)
      end)
      ids = player.room.logic:moveCardsHoldingAreaCheck(ids)
      if #ids > 0 then
        event:setCostData(self, {cards = ids})
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:addToPile(chunrijishi.name, event:getCostData(self).cards, true, chunrijishi.name, player)
    if not player.dead and #player:getPile(chunrijishi.name) > 2 then
      player:broadcastSkillInvoke(chunrijishi.name, 2)
      table.insertIfNeed(room.alive_players, player)
      room:moveCardTo(player:getPile(chunrijishi.name), Card.PlayerHand, player, fk.ReasonJustMove, chunrijishi.name, nil, true, player)
      room:handleAddLoseSkills(player, "hanqing__fenyin|paoxiao|-hanqing__chunrijishi")
    end
  end,
})

chunrijishi:addEffect(fk.EventTurnChanging, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(chunrijishi.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    data.skipped = true
  end,
})

chunrijishi:addAcquireEffect(function (self, player, is_start)
  if not is_start then
    table.removeOne(player.room.alive_players, player)
  end
end)

chunrijishi:addLoseEffect(function (self, player, is_death)
  if not is_death then
    table.insertIfNeed(player.room.alive_players, player)
  end
end)

chunrijishi:addEffect("prohibit", {
  is_prohibited = function(self, from, to, card)
    return card and to and to:hasSkill(chunrijishi.name)
  end,
})

chunrijishi:addEffect(fk.BeforeHpChanged, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(chunrijishi.name)
  end,
  on_refresh = function(self, event, target, player, data)
    data.prevented = true
  end,
})

chunrijishi:addEffect(fk.BeforeMaxHpChanged, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(chunrijishi.name)
  end,
  on_refresh = function(self, event, target, player, data)
    data.prevented = true
  end,
})

return chunrijishi
